$(function () {
    reset();
})
// var password = "";
// $("input[type=password]").blur(function(){
//     password = $(this).val();
// });
function registerUser(){
    layer.open({
        type: 1,
        title: '注册',
        closeBtn: 1,
        area:['400px', '300px'],
        shadeClose: true,
        btn: ['注册', '取消'],
        content: $('#register'),
        btnAlign: 'c',
        yes:function (index, layero) {
            var userName = $("#userNameRe").val().trim();
            var password = $("#passwordRe").val().trim();
            var password2 = $("#passwordRe2").val().trim();
            if (userName == null || userName == '' || userName == undefined){
                layer.alert("请输入用户名");
                return false;
            }
            if (password == null || password == '' || password == undefined){
                layer.alert("请输入密码");
                return false;
            }
            if (password != password2){
                layer.alert("两次输入的密码不一致");
                return false;
            }
            $.ajax({
                url:'/user/registerUser.do',
                type:'post',
                data: {
                    "userName":userName,
                    "password":password
                },
                success:function(data){
                    if (data.code==99) {
                        layer.alert("注册成功")
                    }else {
                        layer.alert(data.info);
                    }
                    $("#userNameRe").val("");
                    $("#passwordRe").val("");
                    $("#passwordRe2").val("");
                    layer.close(index);
                }
            });
        }
    });
}
function reset(){
    $("#userName").val("");
    $("#password").val("");
}

function login(){
    var userName = $("#userName").val().trim();
    var password = $("#password").val().trim();
    // var md5password = $.md5(password);
    if (userName == null || userName == '' || userName == undefined){
        layer.alert("请输入用户名");
        return false;
    }
    if (password == null || password == '' || password == undefined){
        layer.alert("请输入密码");
        return false;
    }
    $.ajax({
        url:'/login/login.do',
        type:'post',
        data: {
            "userName":userName,
            "password":password
        },
        dataType : 'json',
        success:function(data){
            console.log(data);
            if (data.code == 99){
                window.location.href = '/login/welcome.do?token='+ data.data;
            }else {
                layer.alert(data.info);
            }
        }
    });
    //location.href = '/login/login.do?userName=' + userName +'&password='+md5password;
}